﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MINERP.GroupMember.IView;
using MINERP.BLL.GroupMember;
using MINERP.MODEL.GroupMember;

using System.Data;
using System.IO;
using Leadtools.Codecs;
using MINERP.MODEL.FoundationModel;
using System.Windows.Forms;
using MINERP.BLL.Common;
using System.Threading;
using MINERP.COM;
using MINERP.ComControls.Froms;

namespace MINERP.GroupMember.Presenter
{

    public class FrmToolPresenter
    {
        private IFrmTool _view;
        private GroupMemberBLL _bll;
        WorkFlowListBLL _wflBll;
        private bool isImgView = false;//默认为列表显示方式
        private List<string> _picPathList;//用于存入图片的路径列表

        private DataTable _dtSource;//存入照片信息
        private List<BigPicInfo> _ImportPicList;//导入的大图片的信息

        private List<EPByPhotoSpecInfo> _epByPhotoSpecInfoList = new List<EPByPhotoSpecInfo>();//按照片规格统计名称列表
        private WorkShop_Info _workshop = null;//车间信息

        public int notifyOptions; //裁片提示
        public bool Notify;//是否提示

        Thread thGetTask;

        public FrmToolPresenter(IFrmTool view)
        {
            _view = view;
            _bll = new GroupMemberBLL();
            _wflBll = new WorkFlowListBLL();
            _epByPhotoSpecInfoList = _bll.GetEPByPhotoSpecInfoList();
            _workshop = _bll.GetWorkShopInfo();

            DataTransfer.UserId = _view.userid;
        }

        /// <summary>
        /// 查看任务列表
        /// </summary>
        internal void OpenTaskListForm()
        {
            FrmTasks frm = new FrmTasks();
            DataTransfer.SelectedTaskEvent += new SelectedTask(DataTransfer_SelectedTaskEvent);
            frm.ShowDialog();
        }

        /// <summary>
        /// 当任务界面双击某一任务后，工具栏就显示相应的信息
        /// </summary>
        void DataTransfer_SelectedTaskEvent()
        {
            _view.ShowHeaderInfo(DataTransfer.SelectTaskInfo);
            _view.ShowPhotos(DataTransfer.SelectTaskInfo.PhotoList);
            if (DataTransfer.SelectTaskInfo.IsDeisgnTech)//是设计结点则要显示设计的要求与设计的尺寸与PAGENUM数
            {
                _view.ShowDesingPanel();
            }
            else
            {
                //_view.ShowDesingPanel();
                _view.HidenDesignPanel();
            }


            //开启一个线程去更新任务列表
            if (thGetTask == null)
            {
                thGetTask = new Thread(GetNewTask);
                thGetTask.Start();
            }
            else
            {
                if (thGetTask.ThreadState == ThreadState.Stopped || thGetTask.ThreadState == ThreadState.Background || thGetTask.ThreadState == ThreadState.WaitSleepJoin || thGetTask.ThreadState == ThreadState.Suspended)
                {
                    thGetTask = new Thread(GetNewTask);
                    thGetTask.Start();
                }
            }

        }

        public void GetNewTask()//取新的任务列表
        {
            int picCount = 0;
            double picAreaCount = 0.0;
            try
            {
                DataTransfer.taskList = _bll.GetListTask(DataTransfer.UserId, out picCount, out picAreaCount);
            }
            catch (Exception ex)//如果出现异常，此处的异常可以就是多线程的异常，则什么都不做
            {

                WriteLogForCheck.WriteLogFile("组员在多线程取任务时错,出错内容如：" + ex.Message);
                return;
            }


            DataTransfer.PicCount = picCount;
            DataTransfer.PicAreaCount = picAreaCount;

        }

        /// <summary>
        /// 切换列表、图片显示
        /// </summary>
        internal void ChangeView()
        {
            if (!isImgView)
            {
                //显示图片
                isImgView = true;
                if (_picPathList == null || _picPathList.Count < 1)
                {
                    _picPathList = DataTransfer.SelectTaskInfo.PhotoList.Select(p => p.PicPath).ToList();
                }
                _view.ShopPic(_picPathList);
            }
            else
            {
                //显示列表
                isImgView = false;
                _view.ShowPhotos(DataTransfer.SelectTaskInfo.PhotoList);
            }
        }

        #region help methods
        /// <summary>
        /// 根据用户拖入的路径得到该路径下的所有图片信息
        /// </summary>
        /// <param name="strPath"></param>
        /// <returns></returns>
        private void AddPic(string strPath)
        {
            RasterCodecs.Startup();
            if (_ImportPicList == null)
            {
                _ImportPicList = new List<BigPicInfo>();
            }
            //List<BigPicInfo> list = new List<BigPicInfo>();
            //BigPicInfo bpi;
            if (Directory.Exists(strPath))//目录
            {
                DirectoryInfo di = new DirectoryInfo(strPath);
                foreach (var fi in di.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    if (_ImportPicList.Exists(p => p.PicPath == fi.FullName))
                    {
                        if (DialogResult.OK != MessageBox.Show(string.Format("{0}\n\n此片已存是否续继添加？", fi.FullName), "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                        {
                            continue;
                        }
                    }

                    BigPicInfo bi = GetFileInfo(fi);
                    if (bi != null)
                    {
                        _ImportPicList.Add(bi);
                    }
                }
            }
            else if (File.Exists(strPath))//文件
            {
                FileInfo fi = new FileInfo(strPath);

                if (_ImportPicList.Exists(p => p.PicPath == fi.FullName))
                {
                    if (DialogResult.OK != MessageBox.Show(string.Format("{0}\n\n此片已存是否续继添加？", fi.FullName), "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                    {
                        RasterCodecs.Shutdown();
                        return;
                    }
                }

                BigPicInfo bi = GetFileInfo(fi);
                if (bi != null)
                {
                    _ImportPicList.Add(bi);
                }
            }

            RasterCodecs.Shutdown();

            //return list;
        }

        /// <summary>
        /// 得到一个图片文件的信息
        /// </summary>
        /// <param name="fi"></param>
        /// <returns></returns>
        private BigPicInfo GetFileInfo(FileInfo fi)
        {
            //FileInfo fi = new FileInfo(strPath);
            if (fi.Extension == ".jpg" || fi.Extension == ".JPG")
            {
                RasterCodecs codecs = new RasterCodecs();
                BigPicInfo bpi = new BigPicInfo();
                bpi.IsMatchSize = true;
                bpi.PicName = fi.Name;
                bpi.PicPath = fi.FullName;
                CodecsImageInfo img = codecs.GetInformation(fi.FullName, true);
                int resolution = img.XResolution;
                bpi.PixWidth = img.Width;
                bpi.PixHeight = img.Height;
                bpi.Width = (float)img.Width / (float)resolution;//英寸
                bpi.Height = (float)img.Height / (float)resolution;//英寸
                bpi.NUM = 1;//默认是一张
                img.Dispose();
                codecs.Dispose();
                return bpi;
            }
            else
            {
                return null;
            }
        }
        #endregion

        /// <summary>
        /// 用户导片
        /// </summary>
        internal void DoDragPicFromOutSide()
        {
            List<string> paths = _view.DropDirPath;
            foreach (string path in paths)
            {
                AddPic(path);
            }
            //显示
            _view.ShowImportPicList(_ImportPicList);
        }

        /// <summary>
        /// 还原全部图片
        /// </summary>
        internal void LoadOriginalPic()
        {
            //得到原图的路径
            try
            {
                _dtSource = _bll.GetBackUpPhotoInfo(DataTransfer.SelectTaskInfo.OrderProductId);
            }
            catch (Exception ex)
            {

                System.Windows.Forms.MessageBox.Show(ex.Message, "错误", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            _view.ShowPhotoList(_dtSource);
        }
        /// <summary>
        /// 完成非设计工作
        /// </summary>
        internal void CompleteWork(string orderProductRemark)
        {
            if (DataTransfer.SelectTaskInfo.PhotoList.FindIndex(p => !p.IsEdit) != -1)
            {
                if (DialogResult.Yes != MessageBox.Show("还有未 “查看/编辑” 的图片是否要续继完成?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    return;
                }
            }
            //先移动图片，成功后才提交数据库
            if (DataTransfer.IsUseCamero)
            {
                int MoveResult = ChangePicByTime();
                if (MoveResult == -1)
                {
                    MessageBox.Show("请查看已开单下该产品文件夹下的图片是否被都被移走?");
                    return;
                }
                else if (MoveResult == -2)
                {
                    if (DialogResult.Yes != MessageBox.Show("未发现有用Camera Raw保存过的图片，是否要续继完成?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        return;
                    }
                }
                else if (MoveResult == -3)
                {
                    MessageBox.Show("重命名图片时出错，请检查是否有图片正被打开使用，请关闭后再保存!");
                    return;
                }
            }

            //检查图片的尺寸与开单时的尺寸是否一致，如果不一致则提示是否用现在的尺寸覆盖原来的尺寸
            int checkResult = CheckPicSizeAndChange();
            if (checkResult == -1)
            {
                return;
            }
            else if (checkResult == -2)
            {
                MessageBox.Show("程序遇到问题，请关闭组员重新登陆，再次提交，如还遇到问题，请联系上海惟鸿网络,谢谢！");
                return;
            }
            List<PhotoInfo_GM> needModifySizePs = DataTransfer.SelectTaskInfo.PhotoList.Where(p => p.PGMStatus == 1).ToList();
            if (needModifySizePs.Count > 0)
            {
                _bll.ModifyPhotoSize(needModifySizePs);
            }
            _bll.UpdateOrderProductRemark(orderProductRemark, DataTransfer.SelectTaskInfo.OrderProductId);//修改备注
            bool result = _bll.CompleteWork(DataTransfer.SelectTaskInfo.TechId, DataTransfer.UserId, DataTransfer.SelectTaskInfo.OrderProductId,_epByPhotoSpecInfoList,_workshop);

            if (result)//更新成功
            {
                ClearData();
                //清空界面
                //_view.ClearForm();
                //显示列表
                isImgView = false;
                if (DataTransfer.IsAutoGetTask)
                {
                    //自动获取任务
                    TaskInfo t = DataTransfer.taskList.OrderByDescending(or=>or.Priority).ThenBy(s=>s.OrderProductId).FirstOrDefault(tt => tt.status != (int)OrderFlowListStatus.Wait);//默认就是按加急级别排序的
                    if (t != null)
                    {
                        DataTransfer.SelectTaskInfo = t;
                    }
                    else
                    {
                        OpenTaskListForm();
                    }
                }
                else
                {
                    OpenTaskListForm();
                }
            }
            else
            {
                MessageBox.Show("保存异常", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
            }

        }

        /// <summary>
        /// 检查当前照片的尺寸被,-2:出现了异常，已写入日志 -1:取消本次提交(图片有损坏、用户取消提交) 0:一切正常进行提交
        /// </summary>
        /// <returns></returns>
        int CheckPicSizeAndChange()
        {

            RasterCodecs.Startup();
            RasterCodecs codecs = new RasterCodecs();
            CodecsImageInfo imageInfo = null;
            Notify = true;
            try
            {
                foreach (var pi in DataTransfer.SelectTaskInfo.PhotoList)
                {
                    try
                    {
                        imageInfo = codecs.GetInformation(pi.PicPath, true);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("图片有损坏请用PS打开后重新重新保存!    ID:" + pi.PhotoId + "   名称：" + pi.PhotoName);
                        return -1;
                    }
                    //pi.PixHeight = imageInfo.Height;
                    //pi.PixWidth = imageInfo.Width;
                    //pi.Height = (float)imageInfo.Height / imageInfo.YResolution;
                    //pi.Width = (float)imageInfo.Width / imageInfo.XResolution;
                    //pi.PGMStatus = 1;//表示剪过

                    if (Math.Round((float)imageInfo.Width / imageInfo.XResolution, 3, MidpointRounding.AwayFromZero) != Math.Round(pi.Width, 3, MidpointRounding.AwayFromZero) || Math.Round((float)imageInfo.Height / imageInfo.YResolution, 3, MidpointRounding.AwayFromZero) != Math.Round(pi.Height, 3, MidpointRounding.AwayFromZero))
                    {
                        if (Notify)
                        {
                            FrmNotify frm = new FrmNotify(this);
                            frm.msg = "ID:" + pi.PhotoId + "名称:" + pi.PhotoName + "  图片尺寸\n被裁剪，是否要覆盖原来的尺寸，或是取消?\n是：用现在的尺寸覆盖数据库的。\n否：不进行覆盖。\n取消：重新调色";
                            frm.ShowDialog();
                        }
                        if (notifyOptions == 1)//覆盖
                        {
                            pi.PixHeight = imageInfo.Height;
                            pi.PixWidth = imageInfo.Width;
                            pi.Height = (float)imageInfo.Height / imageInfo.YResolution;
                            pi.Width = (float)imageInfo.Width / imageInfo.XResolution;
                            pi.PGMStatus = 1;//表示剪过
                        }
                        else if (notifyOptions == 2)//保持原来的尺寸不变
                        {
                            continue;
                        }
                        else//取消提交
                        {
                            return -1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLogForCheck.WriteLogFile(DateTime.Now + " 在组员提交任务进行照片尺寸比对时出错：" + ex.Message);
                return -2;
            }
            finally
            {
                if (imageInfo != null)
                {
                    imageInfo.Dispose();
                }
                RasterCodecs.Shutdown();

            }
            return 0;
        }

        /// <summary>
        /// 如果是用Camero Raw进行高色的，则删除原来的图片，将修改时间最近的那张图片名称更换为数据里图片名称,如果没有找到，则不删除原来的图片或是重
        /// 命名原来的图片oldPicName_old
        /// </summary>
        /// <returns>0、</returns>
        private int ChangePicByTime()
        {
            int result = 0;//0代表正常
            List<string> allFilesName = new List<string>();

            foreach (var pi in DataTransfer.SelectTaskInfo.PhotoList)
            {
                int lastIndex = pi.PicPath.LastIndexOf('\\');
                int lastPointIndex = pi.PicPath.LastIndexOf('.');
                string picDirPath = pi.PicPath.Substring(0, lastIndex);//图片所在的文件夹目录
                string picName = pi.PicPath.Substring(lastIndex + 1, lastPointIndex - lastIndex - 1);//原图片名


                if (allFilesName == null || allFilesName.Count < 1)
                {
                    allFilesName = Directory.GetFiles(picDirPath, "*.jpg", SearchOption.TopDirectoryOnly).ToList();
                    //取出来的是完整路径

                    string strTempPicName = string.Empty;
                    List<string> tempPicNameList = new List<string>();
                    foreach (var piFullPath in allFilesName)
                    {
                        lastIndex = piFullPath.LastIndexOf('\\');
                        lastPointIndex = piFullPath.LastIndexOf('.');

                        strTempPicName = piFullPath.Substring(lastIndex + 1, lastPointIndex - lastIndex - 1);//原图片名
                        tempPicNameList.Add(strTempPicName);
                    }
                    allFilesName.Clear();
                    allFilesName = tempPicNameList;

                }
                if (allFilesName.Count < 1)
                {
                    return -1;//在文件夹下未找到JPG文件
                }


                //allFilesName.ForEach(a => a = a.Substring(0, a.Length - 4));//去掉所有后缀名
                allFilesName = allFilesName.Distinct().ToList();

                List<string> findPics = allFilesName.FindAll(delegate(string a)//找到那些被Camero Raw保存的图片，不包括原图
                 {
                     if (a.Contains(picName) && a.Length - picName.Length == 2)
                     {
                         return true;
                     }
                     else
                     {
                         return false;
                     }
                 });

                if (findPics.Count < 1)
                {
                    return -2;
                    //什么都不错，只找到原图还未找到Carmero Raw保存过的图片
                }

                //从找到的这些图片中找到修改时间最近的那张，把其余的都删除掉
                if (findPics.Count == 1)//只有一张就不需要找了，就它了
                {
                    try
                    {
                        //将原文件重命名picname_old这种形式
                        if (!File.Exists(picDirPath + "\\" + picName + "_old.jpg"))//如果存在，则说明是返单退回来的单子
                        {
                            File.Move(pi.PicPath, picDirPath + "\\" + picName + "_old.jpg");
                        }
                        else
                        {
                            File.Delete(pi.PicPath);
                        }
                        //重命名最新修改的那个图片文件为原始图片名
                        File.Move(picDirPath + "\\" + findPics.FirstOrDefault() + ".jpg", pi.PicPath);
                    }
                    catch (Exception)
                    {
                        return -3;//在重命名原如图片名后加_old时，或是在重命名最新修改过的图片为原始文件名时出错
                    }

                }
                else
                {
                    DateTime lastestTime = new DateTime(2000, 1, 1), curPicModifyTime;
                    string lastestPicName = string.Empty;

                    foreach (var newPicName in findPics)
                    {
                        curPicModifyTime = File.GetLastWriteTime(picDirPath + "\\" + newPicName + ".jpg");
                        if (lastestTime < curPicModifyTime)
                        {
                            lastestTime = curPicModifyTime;
                            lastestPicName = newPicName;
                        }
                    }

                    //将其它的都删除
                    if (!string.IsNullOrEmpty(lastestPicName))
                    {
                        foreach (var delPicName in findPics.FindAll(a => !a.Equals(lastestPicName)))
                        {
                            try
                            {
                                File.Delete(picDirPath + "\\" + delPicName + ".jpg");
                            }
                            catch { }
                        }
                    }
                    try
                    {
                        //将原文件重命名picname_old这种形式
                        if (!File.Exists(picDirPath + "\\" + picName + "_old.jpg"))//如果存在，则说明是返单退回来的单子
                        {
                            File.Move(pi.PicPath, picDirPath + "\\" + picName + "_old.jpg");
                        }
                        else
                        {
                            File.Delete(pi.PicPath);
                        }
                        //重命名最新修改的那个图片文件为原始图片名
                        File.Move(picDirPath + "\\" + lastestPicName + ".jpg", pi.PicPath);
                    }
                    catch
                    {
                        return -3;//在重命名原如图片名后加_old时，或是在重命名最新修改过的图片为原始文件名时出错
                    }

                }

            }

            return result;//0代表正常 
        }

        /// <summary>
        /// 完成设计的工作
        /// </summary>
        internal void ImportNewDesignedPicAndOver()
        {
            string retMessage;
            bool result = false;
            try
            {
                DataTransfer.SelectTaskInfo.ProductRemark = _view.OrderRemark;
                //result = _bll.CompleteDesinedWork(DataTransfer.SelectTaskInfo.TechId, DataTransfer.UserId, DataTransfer.SelectTaskInfo.IsRebackOrder, DataTransfer.SelectTaskInfo.OrderProductId, _ImportPicList, DataTransfer.IsOriPicOver);
                if ( CheckProductPhotoSize(DataTransfer.SelectTaskInfo,_ImportPicList,out retMessage ))
                {
                     result = _bll.CompleteDesinedWork(DataTransfer.SelectTaskInfo, DataTransfer.UserId, _ImportPicList, DataTransfer.IsOriPicOver,_epByPhotoSpecInfoList,_workshop);
                     if (result)
                     {
                         ClearData();
                         //新空界面
                         //_view.ClearForm();
                     }
                     else
                     {
                         System.Windows.Forms.MessageBox.Show("保存异常" + DataTransfer.SelectTaskInfo.TechId, "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                     }
                }
                else
                {
                    if (DialogResult.OK == MessageBox.Show("您确定还要提交吗？"+retMessage, "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                    {
                        result = _bll.CompleteDesinedWork(DataTransfer.SelectTaskInfo, DataTransfer.UserId, _ImportPicList, DataTransfer.IsOriPicOver, _epByPhotoSpecInfoList, _workshop);
                        if (result)
                        {
                            ClearData();
                            //新空界面
                            //_view.ClearForm();
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("保存异常" + DataTransfer.SelectTaskInfo.TechId, "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                        }
                    }
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("当前结点：" + DataTransfer.SelectTaskInfo.TechId + "错误信息：" + ex.Message);
                return;
            }

           
        }

        /// <summary>
        /// 清除本页面的历史数据
        /// </summary>
        private void ClearData()
        {
            _dtSource = null;
            DataTransfer.taskList.Remove(DataTransfer.taskList.Find(t => t.OrderProductId == DataTransfer.SelectTaskInfo.OrderProductId));
            DataTransfer.SelectTaskInfo = null;


            if (_picPathList != null)
            {
                _picPathList.Clear();
            }
            if (_ImportPicList != null)
            {
                _ImportPicList.Clear();
            }

            _view.ClearForm();
        }
        /// <summary>
        /// 用户查看定单界面
        /// </summary>
        internal void SelectRemark()
        {
            string strRemark = DataTransfer.SelectTaskInfo.ProductRemark;
            if (strRemark == null)
            {
                System.Windows.Forms.MessageBox.Show("找不到需求或客户没有提需求！", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);

            }
            else
            {
                List<Tb_Product_Info> listComposeProduct = new List<Tb_Product_Info>();
                listComposeProduct = _bll.GetComposeProducts(DataTransfer.SelectTaskInfo.OrderProductId);
                if (listComposeProduct != null && listComposeProduct.Count >= 1)
                {
                    _view.showComposeProudct(listComposeProduct);//显示附加产品信息
                }
                else
                {
                    _view.HideComposeProduct();//不显示附加产品列表
                }
                _view.ShowRemark(strRemark);
                List<string> CtmList = _bll.GetCtmList(DataTransfer.SelectTaskInfo.ShopId);
                _view.BindCtm(CtmList);//得到该商户所有的客户列表
            }
        }

        internal void CheckImportPic()
        {
            //查看导片
            if (!DataTransfer.SelectTaskInfo.IsDeisgnTech)
            {
                //do nothing
            }
        }

        internal void DeletePic()
        {
            List<string> selectedPicPath = _view.SelectedPicPath;
            if (selectedPicPath != null)
            {
                foreach (var item in selectedPicPath)
                {
                    var bi = _ImportPicList.FindAll(delegate(BigPicInfo bpi)
                    {
                        if (bpi.PicName == item)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    });
                    if (bi != null)
                    {
                        foreach (var a in bi)
                        {
                            _ImportPicList.Remove(a);
                        }
                    }
                }

                _view.ShowImportPicList(_ImportPicList);
            }
        }

        /// <summary>
        /// 还原选定的图片
        /// </summary>
        internal void RecoverSelectedPic()
        {
            List<string> replacePhotoBarCodeList = _view.SelectedPhotoBarCode;
            //得到原图的路径
            try
            {
                _dtSource = _bll.GetPartsBackUpPhotoInfo(DataTransfer.SelectTaskInfo.OrderProductId, replacePhotoBarCodeList);
            }
            catch (Exception ex)
            {

                System.Windows.Forms.MessageBox.Show(ex.Message, "错误", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            _view.ShowPhotoList(_dtSource);
        }

        internal void LookHistory()
        {
            //FrmHistory_BK frm = new FrmHistory_BK();
            //frm.ShowDialog();
            FrmLookSelftPerformance frm = FrmLookSelftPerformance.GetInstance;
            frm.CurUserId = _view.userid;
            frm.ShowDialog();
        }

        internal void ShowConntecionFrm()
        {
            MINERP.ComControls.frmMain.GetInstance(_view.userid).Show();
        }

        internal void ReBackTask(string rebackRemark)//组员将此单退回给组长重新分配
        {
            //1.修改workorderflowlist的userid=0
            //2.修改workorderflowlist的status=1
            //3.分配时间设为0

            FrmRebackSelect frm = new FrmRebackSelect();
            if (DialogResult.OK != frm.ShowDialog())
            {
                return;
            }
            string strMsg = "";
            //bool result = _bll.ReBackTask(DataTransfer.SelectTaskInfo, out strMsg);
            DataTransfer.SelectTaskInfo.ProductRemark = rebackRemark;//记录退回原因
            bool result = _bll.ReBackTask(DataTransfer.SelectTaskInfo, out strMsg, DataTransfer.RebackType);
            if (result)//退回成功
            {
                //清空界面
                ClearData();
                OpenTaskListForm();
            }
            else
            {
                MessageBox.Show(strMsg);
            }
        }
        internal List<TaskInfo> GetProductList(string inCtmName)
        {
            return _bll.GetCtmProduct(inCtmName);
        }

        /// <summary>
        /// 检查实际照片与模版设置尺寸数量是否一致
        /// </summary>
        /// <param name="taskInfo"></param>
        /// <param name="bigPicInfoList"></param>
        /// <returns></returns>
        internal bool CheckProductPhotoSize(TaskInfo taskInfo,List<BigPicInfo> bigPicInfoList,out string  retMessage)
        {
            return _bll.CheckProductPhotoSize(taskInfo, bigPicInfoList,out retMessage);
        }

        internal void PauseOrderProduct(int orderProductId, int status, string remark, int userId)
        {
             _bll.PauseOrderProduct(orderProductId,status,remark,userId);
        }
       
    }
}
